package com.example.intelligentattendancesystem.mapping;

import com.example.intelligentattendancesystem.pojo.Absence;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AbsenceMapping {
    /**
     * 新增缺勤信息
     * @param absence 缺勤信息
     * @return 修改的条数
     */
    @Insert("insert into t_absence values(#{id}, #{userId}, #{absenceStartTime}, #{absenceEndTime})")
    int insertAbsence(Absence absence);

    /**
     * 通过ID查询用户的缺勤信息
     * @param userId
     * @return
     */
    @Select("select id,user_id as userId ,absence_start_time as absenceStartTime,absence_end_time as absenceEndTime from t_absence where user_id = #{userId}")
    List<Absence> selectAbsenceByUserId(int userId);

    /**
     * 通过账号删除用户某一节课的缺勤记录
     * @param userId
     * @return 修改的条数
     */
    @Delete("delete from t_absence where user_id = #{userId} and absence_start_time=#{absenceStartTime}")
    int deleteAbsence(int userId , String absenceStartTime);

    /**
     * 通过账号删除用户所有缺勤记录
     * @param userId
     * @return 修改的条数
     */
    @Delete("delete from t_absence where user_id = #{userId}")
    int deleteUserAllAbsence(int userId);

    /**
     * 获取所有缺勤表
     * @return  缺勤表
     */
    @Select("select id,user_id as userId ,absence_start_time as absenceStartTime,absence_end_time as absenceEndTime from t_absence")
    List<Absence> selectAllAbsence();

}
